var app = {};
Ext.onReady(function(){
	Ext.QuickTips.init();
	var viewport = Ext.create("Ext.container.Viewport",{
	    layout: 'border',
	    renderTo : 'viewport',
	    items: [
	    new Ext.Component({
	        region: 'north',
	        height: 82,
	       	margins: '0 0 0 0',
	       	contentEl : 'top_panel'
	    }),{
	        region: 'east',
	        title: '其他工具',
	        collapsible: true,
	        collapsed : true,
	        split: true,
	        width: 175, 
	        margins: '0 2 2 0',
	        layout: 'fit'
	    }, {
	        region: 'west',
	        id: "leftPanel",
	        title: '系统管理',
	        split: true,
	        width: 230,
	        minSize: 175,
	        maxSize: 400,
	        collapsible: true,
	        items : [treePanel],
	        margins: '0 0 2 2'
	    },
	    Ext.create("Ext.tab.Panel",{
	    	id : "mainTabPanel",
	        region: 'center', 
	        margins: '0 -3 2 -3',
	        activeTab: 0,     
	        items: []
	    })]
	});
	
	app.viewport = viewport;
	app.mainTabPanel = Ext.getCmp("mainTabPanel");
	app.viewport.doLayout();
	setTimeout(function(){
		Ext.get('loading').remove();
		Ext.get('loading-mask').fadeOut({remove:true});
	}, 250);
});
var store = Ext.create('Ext.data.TreeStore', {
    root: {
        expanded: true,
        children: [
            { text: "detention", leaf: true },
            { text: "homework", expanded: true, children: [
                { text: "book report", leaf: true },
                { text: "alegrbra", leaf: true}
            ] },
            { text: "buy lottery tickets", leaf: true }
        ]
    }
});

var treePanel = Ext.create('Ext.tree.Panel', {
    title: 'Simple Tree',
    width: 200,
    height: 150,
    store: store,
    rootVisible: false,
    listeners: {
           		itemclick:function( v,  record ) {
                if (record.isLeaf) {
                	var newTab = Ext.create("Ext.Component",{
                		title : record.get("text"),
                		iconCls : "tab-1",
                		tabTip : record.get("text"),
                		closable : true,
                		html : K.wrapIframe($path + "/requestStage.do?resId=test")
                	});
                	app.mainTabPanel.add(newTab);
                	app.mainTabPanel.setActive(newTab);
                }
            }
        }
});
